package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark65Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark65 extends BaseMark {

    LayoutWatermark65Binding binding;

    public Mark65(@NonNull Context context) {
        super(context);
    }

    public Mark65(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark65(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark65Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            hideView(binding.bottom);
            int n = binding.mid.getChildCount();
            for (int i = 2; i < n; i++) {
                binding.mid.getChildAt(i).setVisibility(View.GONE);
            }
        } else {
            binding = LayoutWatermark65Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.title, "title65", binding.title);
        setText(binding.binding2, "time65", binding.binding1);
        setTime(binding.binding2, new SimpleDateFormat("yyyy-MM-dd"));
        setWeek(binding.binding3);
        setTime(binding.binding4, new SimpleDateFormat("HH:mm"));

        setText(binding.binding6, "content65", binding.binding5);
        setText(binding.binding8, "weather65", binding.binding7);
        setText(binding.binding10, "person65", binding.binding9);

        setText(binding.binding12, "wrong65", binding.binding11);
        setText(binding.binding14, "fix65", binding.binding13);
        setText(binding.binding16, "louge65", binding.binding15);
        setText(binding.binding18, "loudong65", binding.binding17);

        setText(binding.binding20, "unit65", binding.binding19);
        setText(binding.binding22, "didian65", binding.binding21);
        setText(binding.binding24, "beizhu65", binding.binding23);
        setText(binding.binding26, "wuye65", binding.binding25);
        setText(binding.binding28, "xiaoqu65", binding.binding26);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title65", "标题"));
        list.add(new EditItem("time65", "时间", true));
        list.add(new EditItem("content65", "巡检类型"));
        list.add(new EditItem("weather65", "天气"));
        list.add(new EditItem("person65", "巡检人"));
        list.add(new EditItem("wrong65", "问题备注"));
        list.add(new EditItem("fix65", "维修负责人"));
        list.add(new EditItem("louge65", "楼阁"));
        list.add(new EditItem("loudong65", "楼栋"));
        list.add(new EditItem("unit65", "单元"));
        list.add(new EditItem("didian65", "巡检地点"));
        list.add(new EditItem("beizhu65", "备注"));

        list.add(new EditItem("wuye65", "物业单位"));
        list.add(new EditItem("xiaoqu65", "小区名称"));


        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding2, new SimpleDateFormat("yyyy-MM-dd"));
            setWeek(binding.binding3);
            setTime(binding.binding4, new SimpleDateFormat("HH:mm"));
        } else {
            super.onValueChange(item);
        }
    }
}
